import re
from collections import Counter

def word_count(text):
    words = re.findall(r'\b\w+\b', text.lower())
    return Counter(words)

sample_text = """
Python is powerful, and Python is fast.
It's also easy to learn! Python 3.10 released in 2021.
"""

counts = word_count(sample_text)
print("单词频率统计:")
for word, freq in counts.most_common():
    print(f"'{word}':{freq}次")

char_counts = Counter(sample_text.lower())
print("\n字符频率TOP5:")
for char, count in char_counts.most_common(5):
    print(f"'{char}':{count}次")














def validate_password(password):
    """验证密码强度"""
    strength ={
        'length': len(password) >= 8,
        'has_upper': any(c.isuper() for c in password),
        'has_lower': any(c.islower() for c in password),
        'has_digit': any(c.isdigit() for c in password),
        'has_special': not password.isalnum()
    }


    score = sum(strength.values())



    feedback = []
    if not strength['length']:
        feedback.append("密码长度至少8位")
    if not strength ['has_upper']:
        feedback.append("需要包含大写字母")
    if not strength ['has_lower']:
        feedback.append("需要包含小写字母")
    if not strength ['has_digit']:
        feedback.append("需要包含数字")
    if not strength ['has_special']:
        feedback.append("建议添加特殊字符")


    return{
        'is_vslid': score >= 4,
        'score': f"{score}/5",
        'feedback': feedback
    }

password = ["abc123","Python3","Strong@Pass123","弱密码"]
for pwd in password:
    result = validate_password(pwd)
    print(f"\n密码: {pwd}")
    print(f"强度: {result['score']} | 有效性: {'通过' if result['is_valid']else '不通过'}")
    if result['feedback']:
        print("改进建议:")
        for tip in result['feedback']:
            print(f"- {tip}")












import jieba


text = "自然语言处理是人工智能的重要方向"
words = jieba.luct(text)
print("中文分词结果:", "/".join(words))






import random
import string


def genterate_password(length=12):
    """生成随机密码"""
    chars = (
        string.ascii_uppercase +
        string.ascii_lowercase +
        string.digits +
        "!@#$%^&*"
    )
    while True:
        pwd = ''.join(random.choice(chars)for _ in range(length))
        if validate_password(pwd)['is_vakid']:
            return pwd
print("生成强密码:", genterate_password())